package ren.xbcr.schoolbus.client.fragment;

import android.app.Dialog;
import android.content.DialogInterface;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import android.text.Spannable;
import android.text.style.ForegroundColorSpan;
import android.text.style.StyleSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import ren.xbcr.schoolbus.client.R;
import ren.xbcr.schoolbus.client.util.Constants;

/**
 * Created by Jian on 2015/12/16.
 */
public class ReturnedCallFragment extends DialogFragment {


    public static ReturnedCallFragment newInstance(String message) {
        ReturnedCallFragment f = new ReturnedCallFragment();

        // Supply num input as an argument.
        Bundle args = new Bundle();
        args.putString(Constants.BUNDLE_RETURNED_CALL_MESSAGE, message);
        f.setArguments(args);

        return f;
    }
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        // Use the Builder class for convenient dialog construction
        final String returnedCallMessage = getArguments().getString(Constants.BUNDLE_RETURNED_CALL_MESSAGE);

        LayoutInflater inflater = getActivity().getLayoutInflater();
        View view = inflater.inflate(R.layout.dialog_return_call, null);
        TextView returnCallViewer = (TextView)view.findViewById(R.id.call_return_message_viewer);
        String message = getString(R.string.dialog_returned_call_message);
        returnCallViewer.setText(returnedCallMessage + message, TextView.BufferType.SPANNABLE);
        Spannable s = (Spannable)returnCallViewer.getText();
        s.setSpan(new ForegroundColorSpan(Color.RED), 0, returnedCallMessage.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        s.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, returnedCallMessage.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//        carCodeViewer.setText(returnedCallMessage);

        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setView(view)
//                .setMessage(String.format(getString(R.string.dialog_returned_call_message), returnedCallMessage))
                .setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                    }
                })
                .setCancelable(false);
        // Create the AlertDialog object and return it
        return builder.create();
    }
}
